import * as bm from "/js/baseModule.js";

export class Module extends bm.baseModule {
    constructor(view) {
        super(view);
        this.vue = new Vue({
            el: '.FeedbackCancel_vue',
            data: globalData,
            computed: {
                oneDay: function () {
                    let startTime = globalData.current_demand.bid_win_at;
                    let stime = startTime * 1000;
                    let date = new Date().getTime();
                    let gapMin = Math.floor((date - stime) / 1000 / 60);
                    if (gapMin <= 0) {
                        //防止偶尔出现的js取时间不准确
                        gapMin = 1;
                    }

                    if (gapMin > (60 * 24)) {
                        return false;
                    }
                    return true;
                },
            }
        });
        this.find(".btn").attr("disabled", "false");
    }

    _evt_chooseTab(obj, hit) {
        this.vue.tabType = $(hit).attr('type');
        this.find('.pull-right').removeClass('icon-checkmark');
        if (this.vue.tabType == 'other' && this.vue.text.trim().length > 0) {
            this.find(".btn").removeAttr("disabled");
            return;
        }
        this.find(".btn").attr("disabled", "false");
    }

    /**options展开收回*/
    _evt_optionsShown(obj, hit) {
        $(obj).find('.icon-circle-down').toggleClass('rotate');
        $(obj).parent().find('.options').slideToggle(300);
    }

    // 单选原因
    _evt_clickType(obj, hit) {
        let cur = $(hit).find('.pull-right');
        let type = $(hit).attr('type');
        this.updateType(type);
    }

    // 提交原因
    updateType(type) {
        let that = this;
        this.find('.sendImgPending').removeClass('hide');

        let data = {
            demand_id: globalData.current_demand.id,
            feedback: parseInt(type) || 99,
            feedback_type: 0
        };
        api.feedback(data, {
            succ: function (json) {
                // funs.tip('反馈成功', '您的反馈信息已提交，请等待微信公众号的审核结果通知', 'succ');
                globalData.current_demand.feedback_info.feedback_status = 3;
                globalData.current_demand.punish_bid_point = json.punish_bid_point;
                that.find('.sendImgPending').addClass('hide');
                location.hash = 'project/FeedbackDemand/FeedbackResult';
            },
            fail: function (data) {
                that.find('.sendImgPending').addClass('hide');
                funs.tip(data.msg, '', 'fail');
            }
        });
    }
}
